﻿using System;
using System.Collections.Generic;
#if DEBUG
using System.Diagnostics;
#endif // #if DEBUG
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using FRL.DebtChased.Silverlight.Library;
using FRL.DebtChased.WorkflowObjects;

namespace FRL.DebtChased.WorkflowEditor.WorkflowItemEditors
{

	/// <summary>
	/// Declaration of NotifyManagerCtrl class
	/// Controls for editing the workflow action to notify manager of account
	/// </summary>
	public partial class NotifyManagerCtrl : ActionBaseCtrl
	{

		/////////////////////////////////////////////////////////////
		// Construction

		public NotifyManagerCtrl()
		{

			// Initialize resources
			InitializeComponent();

		}

		/////////////////////////////////////////////////////////////
		// Implementation

		public override List<string> Validate()
		{

			// Declare return variable
			List<string> Ftmp = null;

			// Check controls
			if (txtMessage.Text.Length == 0)
			{
				if (Ftmp == null)
					Ftmp = new List<string>();
				Ftmp.Add("Enter a message for the manager.");
			}

			// Return variable
			return Ftmp;

		}

		public override void UpdateControls(WorkflowAction_Base action)
		{

			// Block update events
			this.BlockUpdateEvents = true;
			{

				// Cast the action
				WorkflowAction_NotifyManager notifyManagerAction = action as WorkflowAction_NotifyManager;
#if DEBUG
				Debug.Assert(notifyManagerAction != null);
#endif // #if DEBUG

				// Set the controls - Priority
				ComboBoxObject.SelectByItemData(cboPriority,(int)notifyManagerAction.Priority);

				// Set the controls - Message
				txtMessage.Text = notifyManagerAction.Message;

			}
			this.BlockUpdateEvents = false;

		}

		public override void UpdateFromControls(ref WorkflowAction_Base action)
		{

			// If the action needs changing...
			if (!(action is WorkflowAction_NotifyManager))
				action = new WorkflowAction_NotifyManager();

			// Cast the action
			WorkflowAction_NotifyManager notifyManagerAction = action as WorkflowAction_NotifyManager;
#if DEBUG
			Debug.Assert(notifyManagerAction != null);
#endif // #if DEBUG

			// Update object - Priority
			notifyManagerAction.Priority = (WorkflowAction_Base.ePriority)(cboPriority.SelectedItem as ComboBoxObject).ItemData;

			// Set the controls - Message
			notifyManagerAction.Message = txtMessage.Text;

		}

		public override void InitializeControls()
		{

			// Set the controls - Priority
			WorkflowAction_Base.LoadPriorityDropDown(cboPriority, WorkflowAction_Base.ePriority.High);

			// unblock update events
#if DEBUG
			Debug.Assert(this.BlockUpdateEvents);
#endif // #if DEBUG
			this.BlockUpdateEvents = false;

			// setup controls
			_setupControls();

		}

		/////////////////////////////////////////////////////////////
		// Event handlers

		private new void ActionBaseCtrl_Loaded(object sender, RoutedEventArgs e)
		{

			// Call base-class function
			base.ActionBaseCtrl_Loaded(sender, e);

			// setup controls
			_setupControls();

		}

		private void cboPriority_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{

			// Shortcuts
			if (this.BlockUpdateEvents)
				return;

			// If this control is in a tabbed panel...
			if (m_pnlAddAction != null)
				m_pnlAddAction.UpdateFromCtrl(this);

		}

		private void txtMessage_TextChanged(object sender, EventArgs e)
		{

			// Shortcuts
			if (this.BlockUpdateEvents)
				return;

			// If this control is in a tabbed panel...
			if (m_pnlAddAction != null)
				m_pnlAddAction.UpdateFromCtrl(this);

		}

		/////////////////////////////////////////////////////////////
		// Operations

		private void _setupControls()
		{

			// Enable/disable controls

			// Show/hide controls

			// Show/hide controls- Email Options

		}

	}

}

